package com.stars.base.entity;

import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2022/10/27 16:27
 * @description : 树节点实体Bean
 */
public class TreeNode {
    private String id;

    /**
     * 节点唯一标识
     */
    private String value;
    /**
     * 节点标题
     */
    private String label;
    /**
     * 父节点ID
     */
    private String pId;
    /**
     * 是否叶子节点，主要懒加载使用
     */
    private boolean isLeaf;

    /**
     * 是否禁用
     */
    private boolean disabled;

    /**
     * 子节点
     */
    private List<TreeNode> children = new ArrayList<>();
    /**
     * 其他业务属性
     */
    private JSONObject attr = new JSONObject();

    public TreeNode() {
    }

    public TreeNode(String value, String label, String pId) {
        this.value = value;
        this.label = label;
        this.pId = pId;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getpId() {
        return pId;
    }

    public void setpId(String pId) {
        this.pId = pId;
    }

    public boolean getIsLeaf() {
        return isLeaf;
    }

    public void setIsLeaf(boolean leaf) {
        isLeaf = leaf;
    }

    public List<TreeNode> getChildren() {
        return children;
    }

    public boolean isLeaf() {
        return isLeaf;
    }

    public void setLeaf(boolean leaf) {
        isLeaf = leaf;
    }

    public boolean isDisabled() {
        return disabled;
    }

    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

    public void setChildren(List<TreeNode> children) {
        this.children = children;
    }

    public JSONObject getAttr() {
        return attr;
    }

    public void setAttr(JSONObject attr) {
        this.attr = attr;
    }

    public JSONObject toJSON(){
        JSONObject obj = new JSONObject();

        obj.put("value",this.value);
        obj.put("label",this.label);
        obj.put("pId",this.pId);
        obj.put("children",this.children);
        obj.put("attr",this.attr);

        return obj;
    }

    @Override
    public String toString() {
        return toJSON().toJSONString();
    }
}
